package zouhaotian.rbac.view;

import zouhaotian.rbac.domain.entity.Role;
import zouhaotian.rbac.service.array.DeptService;
import zouhaotian.rbac.util.SingletonFactory;

import java.util.Scanner;

public class MainView {

    public static final String MENU = """
            --------------------
                 RBAC 系统
            --------------------
               | 0...退出系统 |
               | 1...部⻔管理 |
               | 2...⻆⾊管理 |
               | 3...⽤户管理 |
            --------------------
            请输入选项:""";
    public static Scanner input;

    static {
        input = new Scanner(System.in);
    }

    private final DeptView deptView;
    private final RoleView roleView;
    private final UserView userView;

    private MainView() {
        deptView = SingletonFactory.getInstance(DeptView.class);
        roleView = SingletonFactory.getInstance(RoleView.class);
        userView = SingletonFactory.getInstance(UserView.class);
    }

    /**
     * 显示界面
     */
    public void show() {
        String menuChoice;

        do {
            System.out.print(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0" -> System.out.println("成功退出系统，欢迎再次使用！");
                case "1" -> deptView.show();
                case "2" -> roleView.show();
                case "3" -> userView.show();
                default -> System.out.println("输入非法，请输入正确菜单编号！");
            }

        } while (!"0".equals(menuChoice));
        input.close();
    }

}

